package automaty;

import java.awt.Color;
import java.util.HashMap;

import komorki.Komorka;

import stany.State;


public abstract class Automat <T extends Automat>{
	protected int row;
	protected int column;
	protected Komorka[][] komorki;
	protected State state;
	protected HashMap<Color, Integer> map;
	
	public Automat(int row, int column, Komorka[][] kom,State s) {
		super();
		this.row = row;
		this.column = column;
		komorki = kom;
		state = s;
	}
	
	abstract public T getClone(int r, int c, Komorka[][] k);
	
	public void clean(){
		for(int i = 0; i < row; i++)
			for(int j = 0; j < column; j++)
				komorki[i][j].setDefinitiveColor(state.deadState());
	}
	public void random(){
		for(int i = 0; i < row; i++)
			for(int j = 0; j < column; j++){
				komorki[i][j].setDefinitiveColor(state.randomState());
			}
	}
	
	public void changeState() {
		
		for(int i = 0; i < row; i++){
			for(int j = 0; j < column; j++){
				checkNeighbour(i, j);
			}
		}
	}
	
	
	public State getState() {
		return state;
	}
	abstract protected void checkNeighbour(int row, int column);
	
}
